package com.orionlily.redis3t.idempotence;

import com.orionlily.redis3t.entity.OpVersion;
import com.orionlily.redis3t.service.OpVersionService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author li.lc
 */
@RestController
@RequestMapping("/opVersion")
public class OpVersionController {

    @Resource(name = "opVersionService")
    private OpVersionService opVersionService;

    @PostMapping()
    public void addIdempotence(@RequestBody OpVersion opVersion){
        OpVersion tempOpVersion = opVersionService.queryById(opVersion.getId());
        opVersion.setVersion(tempOpVersion.getVersion());
        int i = opVersionService.updateWithVersion(opVersion);
        System.out.println(Thread.currentThread() + "添加" + (i > 0 ? "成功":"失败"));
    }
}
